﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Text;
using MiragePWF.Common.Commons;
using MiragePWF.NH.Repositories;
using MiragePWF.NH.TestingBase;
using MiragePWF.NH.UOW;
using NUnit.Framework;
using Wolfut.MirageEE.Domain.Common;
using Wolfut.MirageEE.Kernal.Common;

namespace Wolfut.MirageEE.Server.Test.ServerTest
{
    [TestFixture]
    public class ServerTestBase<T> : DatabaseTestFixtureBase
    {
        protected IList<T> baseLists = new List<T>();
        [TestFixtureSetUp]
        public void Initialize()
        {
            InitializeFramework();
            CreateData();
            SaveData();
        }
        [SetUp]
        public void TestInitialize()
        {
            UnitOfWork.Current.Clear();
        }

        [TearDown]
        public void TestCleanUp()
        {
            DisposeUnitOfWork();
        }
        public override void SetupDatabase(NHibernate.ISession session)
        {

        }

        protected virtual void CreateData()
        {
            Repository<T>.DeleteAll();
            UnitOfWork.Current.TransactionalFlush();
        }
        protected virtual void SaveData()
        {
            this.SaveObjects(baseLists);
             UnitOfWork.Current.TransactionalFlush();
        }

        protected void SaveObjects(IEnumerable<T> objects) 
        {
            foreach (T obj in objects)
            {
                UnitOfWork.CurrentSession.Save(obj);
            }
        }



    }
}